<template>
  <rx-dialog @handOk="handleSubmit" @cancel="cancel">
    <rx-layout>
      <div slot="center">
        <a-form-model ref="form" :model="mdl" :rules="rules">
          <a-form-model-item style="display: none">
            <a-input v-model="mdl.id"/>
          </a-form-model-item>
          <a-row>
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.groupName','分组名称')" prop="i18nJson">
                  <rx-input-i18n :placeholder="i18n('form.groupName','分组名称','input')"
                                 v-model="mdl.i18nJson"
                  />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.enabledOrNot','是否启用')" prop="enabled">
                <a-radio-group name="radioGroup" default-value="yes" v-model="mdl.enabled">
                  <a-radio value="yes">{{i18n('yes','是')}}</a-radio>
                  <a-radio value="no">{{i18n('no','否')}}</a-radio>
                </a-radio-group>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row v-if="isGroup&&mdl.dimId!='-1'">
            <a-col :span="24">
              <a-form-model-item :labelCol="labelCol1" :wrapperCol="wrapperCol1" :label="i18n('form.dimension','组织维度')" prop="dimId">
                <a-select  :placeholder="i18n('form.dimension','组织维度','select')" v-model="mdl.dimId" :getPopupContainer="p=>p.parentNode" allowClear>
                  <a-select-option v-for="dim in dims" :value="dim.dimId" :key="dim.dimId">{{dim.name}}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </rx-layout>
  </rx-dialog>
</template>
<script>
  import osPropertiesGroupApi from '@/api/user/org/osPropertiesGroup'
  import OsDimensionApi from '@/api/user/org/osDimension'
  import {BaseFormModel, RxDialog,Util} from "@lowcode/jpaas-common-lib";

  export default {
    name: 'osPropertiesGroupEdit',
    mixins: [BaseFormModel],
    components: {
      RxDialog,
    },
    props:{
      layerid: String,
      lydata: Object,
      destroy: Function,
      isGroup:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        rules: {
          dimId: [{required: this.isGroup, message: this.i18n('form.dimension','组织维度','select'), trigger: 'change'}],
          enabled: [{required: true, message: this.i18n('form.enabledOrNot','是否启用','select'), trigger: 'change'}],
          /*name: [{required: true, message: this.i18n('form.groupName','分组名称','input'), trigger: 'change'}],*/
          i18nJson: [{required: true, message: this.i18n('form.groupName','分组名称','input'), trigger: 'change'}],
        },
        dims:[],
        mdl:{
          name:"",
          enabled:"yes",
          dimId:"",
           i18nJson:""
        },
      }
    },
    created(){
      if(this.isGroup){
        this.getDims();
      }
    },
    methods: {
      i18n(name,text,key){
            return this.$ti18(name,text,"osPropertiesGroup",key);
      },
      getDims(){
        OsDimensionApi.getDimList().then(res=>{
          this.dims=res.data;
        });
      },
      get(id) {
        return osPropertiesGroupApi.get(id);
      },
      save(values) {
        if(!this.isGroup&&values.dimId==""){
          values.dimId="-1";
        }
        return osPropertiesGroupApi.save(values);
      },
      cancel(){
        Util.closeWindow(this, "cancel");
      }
    },
    watch:{
      "mdl.dimId":function (val,oldval) {
        if(val!=""){
          this.getDims();
        }
      }
    }
  }
</script>
